package com.service.ua;

import com.bpms.common.CommonUtil;
import com.bpms.common.Db;
import com.bpms.common.VO;
import com.bpms.common.VOList;
import com.bpms.esb.IService;

public class Checkuserrole implements IService {
	/**
	 * 输入参数
	 * userid	用户id
	 * 输出参数
	 * perms  权限对象
	 * result 0000成功 1111失败 9999其他
	 * msg 描述
	 */
	public VO exec(VO args) {
		
		VO info=new VO();
		if(args==null) {
			info.setAttr("result", "9999");
			info.setAttr("msg", "1007");
			return info;
		}
		try {
			Db j=new Db();
			StringBuffer userSql=new StringBuffer();
			userSql.append("select c.permid,c.permname from bpm_userrole a ");
			userSql.append("left join bpm_roleperm b on a.roleid=b.roleid ");
			userSql.append("left join bpm_perm c on b.permid=c.permid");
			userSql.append(" where a.userid='");
			userSql.append(args.getAttr("USERID"));
			userSql.append("' and c.val='02' group by c.permid,c.permname");
			
			VOList permlist=j.readAll(new VO(), userSql.toString());
			if(permlist.listData.size()==0)
			{
				info.setAttr("result", "9999");
				info.setAttr("msg", "1006");
				return info;
			}
			
			info.setAttr("result", "0000");
			VO perms=new VO();
			for(int i=0;i<permlist.listData.size();i++){
				VO temp=(VO)permlist.listData.get(i);
				perms.setAttr(temp.getAttr("permid"), temp.getAttr("permname"));
			}
			info.setObj("perms", perms);
			return info;
			
		} catch (Exception e) {
			CommonUtil.debug("ua.Checkuserrole exception",e);
			//e.printStackTrace();
			info.setAttr("result", "9999");
			info.setAttr("msg", "1007");
			return info;
		}
		
	
	}

}
